#include "InetAddress.hh"

InetAddress::InetAddress(string ip, unsigned short port) {
    _addr.sin_family = AF_INET;
    _addr.sin_port = ::htons(port);
    _addr.sin_addr.s_addr = ::inet_addr(ip.c_str());
}

InetAddress::InetAddress(const struct sockaddr_in& addr) 
: _addr(addr) {

}

string InetAddress::Get_ip() {
    return string(::inet_ntoa(_addr.sin_addr));
}

unsigned short InetAddress::Get_port() {
    return ::ntohs(_addr.sin_port);
}

struct sockaddr_in* InetAddress::Get_addrptr() {
    return &_addr;
}

InetAddress::~InetAddress() {
    
}